package com.ksd.pug.controller.indexcategory;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ksd.pug.service.indexcategory.IIndexCategoryService;
import com.ksd.pug.pojo.IndexCategory;
import com.ksd.pug.vo.IndexCategoryVo;
import com.ksd.pug.commons.enums.ResultStatusEnumA;
import com.ksd.pug.commons.ex.PugValidationException;
import com.ksd.pug.commons.utils.fn.asserts.Vsserts;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import com.ksd.pug.controller.BaseController;
import java.util.List;

/**
 * IndexCategoryController
 * 创建人:yykk<br/>
 * 时间：2022-05-06 23:48:13 <br/>
 * 源码下载：前台代码 git clone https://gitee.com/kekesam/kuangstudy-pug-ui.git
 * 飞哥B站地址：后台代码 git clone https://gitee.com/kekesam/kuangstudy-pug-parent.git
 * @version 1.0.0<br/>
 *
*/

@RestController
@RequiredArgsConstructor
@Slf4j
public class IndexCategoryController extends BaseController{

    private final IIndexCategoryService indexcategoryService;


    /**
     * 查询首页分类列表信息
     * @path : /admin/indexcategory/load
     * @method: findIndexCategorys
     * @result : List<IndexCategory>
     * 创建人:yykk
     * 创建时间：2022-05-06 23:48:13
     * @version 1.0.0
     * @return
     */
    @GetMapping("/indexcategory/load")
    public List<IndexCategory> findIndexCategoryList() {
        return indexcategoryService.findIndexCategoryList();
    }

	/**
	 * 查询首页分类列表信息并分页
	 * @path : /admin/indexcategory/list
     * @method: findIndexCategorys
     * @param : indexcategoryVo
     * @result : IPage<IndexCategory>
	 * 创建人:yykk
	 * 创建时间：2022-05-06 23:48:13
	 * @version 1.0.0
	*/
    @PostMapping("/indexcategory/list")
    public IPage<IndexCategory> findIndexCategorys(@RequestBody IndexCategoryVo indexcategoryVo) {
        return indexcategoryService.findIndexCategoryPage(indexcategoryVo);
    }


    /**
     * 根据首页分类id查询明细信息
     * @method: get/{id}
     * @path : /admin/indexcategory/get/{id}
     * @param : id
     * @result : IndexCategory
     * 创建人:yykk
     * 创建时间：2022-05-06 23:48:13
     * @version 1.0.0
    */
    @GetMapping("/indexcategory/get/{id}")
    public IndexCategory getIndexCategoryById(@PathVariable("id") String id) {
        if(Vsserts.isEmpty(id)){
           throw new PugValidationException(ResultStatusEnumA.ID_NOT_EMPTY);
        }
        return indexcategoryService.getIndexCategoryById(new Long(id));
    }


	/**
	 * 保存和修改首页分类
     * @method: saveupdate
	 * @path : /admin/indexcategory/save
     * @param : indexcategory
     * @result : IndexCategory
	 * 创建人:yykk
	 * 创建时间：2022-05-06 23:48:13
	 * @version 1.0.0
	*/
    @PostMapping("/indexcategory/saveupdate")
    public IndexCategory saveupdateIndexCategory(@RequestBody IndexCategory indexcategory) {
        return indexcategoryService.saveupdateIndexCategory(indexcategory);
    }


    /**
	 * 根据首页分类id删除首页分类
     * @method: delete/{id}
     * @path : /admin/indexcategory/delete/{id}
     * @param : id
     * @result : int
	 * 创建人:yykk
	 * 创建时间：2022-05-06 23:48:13
	 * @version 1.0.0
	*/
    @PostMapping("/indexcategory/delete/{id}")
    public int deleteIndexCategoryById(@PathVariable("id") String id) {
        if(Vsserts.isEmpty(id)){
            throw new PugValidationException(ResultStatusEnumA.ID_NOT_EMPTY);
        }
        return indexcategoryService.deleteIndexCategoryById(new Long(id));
    }


   /**
   	 * 根据首页分类ids批量删除首页分类
     * @method: indexcategory/delBatch
     * @path : /admin/indexcategory/delBatch
     * @param : indexcategoryVo
     * @result : boolean
   	 * 创建人:yykk
   	 * 创建时间：2022-05-06 23:48:13
   	 * @version 1.0.0
   	*/
    @PostMapping("/indexcategory/delBatch")
    public boolean delIndexCategory(@RequestBody IndexCategoryVo indexcategoryVo) {
        log.info("你要批量删除的IDS是:{}", indexcategoryVo.getBatchIds());
        if (Vsserts.isEmpty(indexcategoryVo.getBatchIds())) {
            throw new PugValidationException(ResultStatusEnumA.ID_NOT_EMPTY);
        }
        return indexcategoryService.delBatchIndexCategory(indexcategoryVo.getBatchIds());
    }

}